package com.gitee.neuray.security.mail.util;

/*import com.sun.image.codec.jpeg.JPEGCodec;
import com.sun.image.codec.jpeg.JPEGEncodeParam;
import com.sun.image.codec.jpeg.JPEGImageEncoder;*/
import org.springframework.core.io.ClassPathResource;

/*import javax.swing.*;
import java.awt.*;
import java.awt.image.BufferedImage;*/
import java.io.ByteArrayOutputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.List;

/**
 * @auther: zhuqz
 * @date: 2020/3/24 15:57
 * @description: 生日邮件相关模板、附件
 */
public class BirthDayUtil {
    //生日邮件监控
    public  static  final String asr = "zhuqz@neuray.cn";
   /*private static final String template = "<!DOCTYPE html>\n" +
            "<html>\n" +
            "<head>\n" +
            "   <meta charset=\"utf-8\">\n" +
            "   <title>生日快乐</title>\n" +
            "</head>\n" +
            " \n" +
            "<body class=\"\">\n" +
            "<h1>+name+：</h1>\n" +
            "<h2>今天是你的生日，祝你生日快乐，我们一起给你大大的拥抱，送上最温暖的心意。</h2>\n" +
           "<h2>愿过去一年里你所有的努力与付出，都能在今天化作成长的幸福。</h2>\n" +
           "<h2>崭新的下一年，期待我们继续一路同行，分享这段旅途所有的风景和心情！</h2>\n" +
            "<img src=\"\" alt='img'>\n" +
           "<img src=\"\" alt='img'>\n" +
           "<img src=\"\" alt='img'>\n" +
            "</body>\n" +
            "</html>";*/
   private static final String template = "<!DOCTYPE html> \n" +
           "            <html> \n" +
           "            <head> \n" +
           "               <meta charset=\\utf-8\\> \n" +
           "               <title>生日快乐</title> \n" +
           "         <style type=\"text/css\">\n" +
           "          .box{ \n" +
           "            font-size: 20px; \n" +
           "            color:#FF6600; \n" +
           "            margin: 10px;\n" +
           "            animation: changeshadow 1s  ease-in  infinite ;\n" +
           "            -webkit-animation: changeshadow 1s linear infinite;\n" +
           "            -moz-animation: changeshadow 1s linear infinite;\n" +
           "            -ms-animation: changeshadow 1s linear infinite;\n" +
           "            -o-animation: changeshadow 1s linear infinite;\n" +
           "          }  \n" +
           "          @keyframes changeshadow {  \n" +
           "            0%{ text-shadow: 0 0 4px #FF6600}  \n" +
           "            50%{ text-shadow: 0 0 40px #FF6600}  \n" +
           "            100%{ text-shadow: 0 0 4px #FF6600}  \n" +
           "          }\n" +
           "          @-webkit-keyframes changeshadow {\n" +
           "            0%{ text-shadow: 0 0 4px #FF6600}  \n" +
           "              50%{ text-shadow: 0 0 40px #FF6600}  \n" +
           "              100%{ text-shadow: 0 0 4px #FF6600}  \n" +
           "          }\n" +
           "          @-moz-keyframes changeshadow {\n" +
           "            0%{ text-shadow: 0 0 4px #FF6600}  \n" +
           "              50%{ text-shadow: 0 0 40px #FF6600}  \n" +
           "              100%{ text-shadow: 0 0 4px #FF6600}  \n" +
           "          }\n" +
           "          @-ms-keyframes changeshadow {\n" +
           "            0%{ text-shadow: 0 0 4px #FF6600}  \n" +
           "              50%{ text-shadow: 0 0 40px #FF6600}  \n" +
           "              100%{ text-shadow: 0 0 4px #FF6600}  \n" +
           "          }\n" +
           "          @-o-keyframes changeshadow {\n" +
           "            0%{ text-shadow: 0 0 4px #FF6600}  \n" +
           "              50%{ text-shadow: 0 0 40px #FF6600}  \n" +
           "              100%{ text-shadow: 0 0 4px #FF6600}  \n" +
           "          }\n" +
           "        </style>\n" +
           "</head>           \n" +
           "<body> \n" +
           " <div>\n" +
           "      <img src=\"\" alt='img'>\n" +
           "　　  <span class=\"box\" style=\"position:absolute; left:10px; top:5px\">\n" +
           "        <i>\n" +
           "        +name+：<br>\n" +
           "        今天是你的生日，祝你生日快乐，我们一起给你大大的拥抱，送上最温暖的心意。<br>\n" +
           "        愿过去一年里你所有的努力与付出，都能在今天化作成长的幸福。<br>\n" +
           "        崭新的下一年，期待我们继续一路同行，分享这段旅途所有的风景和心情！\n" +
           "        </i>\n" +
           "      </span>\n" +
           "  </div>\n" +
           " </body> \n" +
           "</html>";
    private static final String template2 = "<!DOCTYPE html> \n" +
           "            <html> \n" +
           "            <head> \n" +
           "               <meta charset=\\utf-8\\> \n" +
           "               <title>生日快乐</title> \n" +
           "         <style type=\"text/css\">\n" +
           "          .box{ \n" +
           "            font-size: 20px; \n" +
           "            color:#000000; \n" +
           "            margin: 10px;\n" +
           "            animation: changeshadow 1s  ease-in  infinite ;\n" +
           "            -webkit-animation: changeshadow 1s linear infinite;\n" +
           "            -moz-animation: changeshadow 1s linear infinite;\n" +
           "            -ms-animation: changeshadow 1s linear infinite;\n" +
           "            -o-animation: changeshadow 1s linear infinite;\n" +
           "          }  \n" +
           "          @keyframes changeshadow {  \n" +
           "            0%{ text-shadow: 0 0 4px #000000}  \n" +
           "            50%{ text-shadow: 0 0 40px #000000}  \n" +
           "            100%{ text-shadow: 0 0 4px #000000}  \n" +
           "          }\n" +
           "          @-webkit-keyframes changeshadow {\n" +
           "            0%{ text-shadow: 0 0 4px #000000}  \n" +
           "              50%{ text-shadow: 0 0 40px #000000}  \n" +
           "              100%{ text-shadow: 0 0 4px #000000}  \n" +
           "          }\n" +
           "          @-moz-keyframes changeshadow {\n" +
           "            0%{ text-shadow: 0 0 4px #000000}  \n" +
           "              50%{ text-shadow: 0 0 40px #000000}  \n" +
           "              100%{ text-shadow: 0 0 4px #000000}  \n" +
           "          }\n" +
           "          @-ms-keyframes changeshadow {\n" +
           "            0%{ text-shadow: 0 0 4px #000000}  \n" +
           "              50%{ text-shadow: 0 0 40px #000000}  \n" +
           "              100%{ text-shadow: 0 0 4px #000000}  \n" +
           "          }\n" +
           "          @-o-keyframes changeshadow {\n" +
           "            0%{ text-shadow: 0 0 4px #000000}  \n" +
           "              50%{ text-shadow: 0 0 40px #000000}  \n" +
           "              100%{ text-shadow: 0 0 4px #000000}  \n" +
           "          }\n" +
           "        </style>\n" +
           "</head>           \n" +
           "<body> \n" +
           " <div>\n" +
           "      <img src=\"\" alt='img'>\n" +
           "　　  <span class=\"box\" style=\"position:absolute; left:10px; top:5px\">\n" +
           "        <i>\n" +
           "        +name+：<br><br>\n" +
           "        今天是你的生日，祝你生日快乐，<br>我们一起给你大大的拥抱，送上最温暖的心意。<br><br>\n" +
           "        愿过去一年里你所有的努力与付出，<br>都能在今天化作成长的幸福。<br><br>\n" +
           "        崭新的下一年，期待我们继续一路同行，<br>分享这段旅途所有的风景和心情！\n" +
           "        </i>\n" +
           "      </span>\n" +
           "      <img src=\"\" alt='img'  style=\"position:absolute; left:10px; top:320px\">\n" +
           "  </div>\n" +
           " </body> \n" +
           "</html>";
    //替换人名字 季节图片
    public  static String getTemplate(String name,String pic,String pic2){
         String tempTemplate = template2;
         String res =tempTemplate.replace("+name+",name).replace("+backPic+",pic).replace("+backPic2+",pic2);
         return res;
    }
    /**
     * 给图片添加水印
     *
     * @param markContent
     *            水印的文字
     * @param markContentColor
     *            水印文字的颜色
     * @param qualNum
     *            图片质量
     * @return
     */
    /*public static byte[] createMark(byte[] bytes, List<String[]> markContent,
                              Color markContentColor, float qualNum) {

        Font font = new Font("宋体", Font.BOLD+ Font.ITALIC, 20);//水印字体，大小
        float alpha = 1.0f;//设置水印透明度 默认为1.0  值越小颜色越浅
        ImageIcon imgIcon = new ImageIcon(bytes);
        Image theImg = imgIcon.getImage();
        int width = theImg.getWidth(null);
        int height = theImg.getHeight(null);
        BufferedImage bimage = new BufferedImage(width, height,
                BufferedImage.TYPE_INT_RGB);
        Graphics2D g = bimage.createGraphics();
        g.setColor(markContentColor);
        g.setBackground(Color.white);
        g.setFont(font);              //设置字体
        g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, alpha));//设置水印文字透明度

        g.drawImage(theImg, 0, 0, null);
        for(String[] strs : markContent){
            int x = Integer.parseInt(strs[0]);
            int y = Integer.parseInt(strs[1]);
            String content = strs[2];
            g.drawString(content, x, y); // 添加水印的文字和设置水印文字出现的内容
        }

        g.dispose();
        try {
            ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
            JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(byteArrayOutputStream);
            JPEGEncodeParam param = encoder.getDefaultJPEGEncodeParam(bimage);
            param.setQuality(qualNum, true);
            encoder.encode(bimage, param);
            FileOutputStream out = new FileOutputStream("e:/birthday1.jpg");
            out.write(byteArrayOutputStream.toByteArray());
            out.close();
            return byteArrayOutputStream.toByteArray();
        } catch (Exception e) {
            System.out.println("处理生日邮件水印失败");
        }
        return null;
    }
*/

    /*public static boolean createMark(String filePath, String markContent,
                              Color markContentColor, float qualNum) {
        ClassPathResource resource1 = null;
        try {
            resource1 = new ClassPathResource("birthpic/birthday2.jpg");
        } catch (Exception e) {

            resource1 = new ClassPathResource("birthpic/birthday2.jpg");
        }
        byte[] bytes = new byte[0];
        try {
            bytes = EmailCommon.fileToBytes(resource1.getInputStream());
        } catch (IOException e) {
            e.printStackTrace();
        }
        ImageIcon imgIcon = new ImageIcon(bytes);
        Image theImg = imgIcon.getImage();
        int width = theImg.getWidth(null);
        int height = theImg.getHeight(null);
        BufferedImage bimage = new BufferedImage(width, height,
                BufferedImage.TYPE_INT_RGB);
        Graphics2D g = bimage.createGraphics();
        g.setColor(markContentColor);
        g.setBackground(Color.white);
        g.drawImage(theImg, 0, 0, null);
        g.drawString(markContent, width / 5, height / 5); // 添加水印的文字和设置水印文字出现的内容
        g.dispose();
        try {
            ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
            FileOutputStream out = new FileOutputStream(filePath);

            JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(byteArrayOutputStream);
            JPEGEncodeParam param = encoder.getDefaultJPEGEncodeParam(bimage);
            param.setQuality(qualNum, true);
            encoder.encode(bimage, param);
            out.write(byteArrayOutputStream.toByteArray());
            out.close();
        } catch (Exception e) {
            return false;
        }
        return true;
    }*/

}